<template>
	<view>
		<uni-list :border="true">
			<!-- 右侧带角标 -->
			<uni-list-chat clickable v-for="(item,index) in list" :title="item.goods_name" :key="item.goods_id" :avatar="item.goods_small_logo" :note="item.goods_price | toFixed" @click="gotoDetail(item.goods_id)"></uni-list-chat>
		</uni-list>
	</view>
</template>

<script>
	import { getGoodsList } from '../../api/index.js'
	export default {
		data() {
			return {
				list: [],
				obj: {
					query: '',
					cid: '',
					pagenum: 1,
					pagesize: 10
				},
				isLoading: false,
				total: 0
			}
		},
		onLoad(options) {
			this.obj = { ...this.obj, ...options }
			this.getGoodsList()
		},
		methods: {
			async getGoodsList() {
				this.isLoading = true
				const res = await getGoodsList(this.obj)
				this.total = res.message.total
				this.list = [...this.list, ...res.message.goods]
				this.isLoading = false
			},
			gotoDetail(id) {
				uni.navigateTo({
					url: `/subpkg/goods_detail/goods_detail?id=${id}`
				})
			}
		},
		filters: {
			toFixed(val) {
				return val.toFixed(2)
			}
		},
		onReachBottom() {
			if (this.list.length >= this.total) return uni.$showMsg("数据加载完毕")
			if (this.isLoading) return
			this.obj.pagenum++
			this.getGoodsList()
		},
		onPullDownRefresh() {
			this.obj.pagenum = 1,
			this.list = [],
			this.isLoading = false,
			this.total = 0
			this.getGoodsList()
			uni.stopPullDownRefresh()
		}
	}
</script>

<style lang="scss">

</style>
